<template>
  <div class="register">
    <van-nav-bar title="嗨购商城" left-arrow @click-left="onClickLeft" />

    <van-form @submit="onSubmit">
      <van-cell-group>
        <van-field
          v-model="tel"
          name="tel"
          label="电话号码"
          placeholder="请输入您的手机号.."
        />
      </van-cell-group>
      <div style="margin: 16px">
        <van-button
          round
          block
          color="red"
          :disabled="!flag"
          native-type="submit"
        >
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script setup>
import { ref, computed } from "vue";
import { docheckphone } from "@/api/user.js";
import { useRouter } from "vue-router";
const router = useRouter();
const onClickLeft = () => history.back();
const tel = ref("");
const flag = computed(() => /^1[3-9]\d{9}$/.test(tel.value));
const onSubmit = (user) => {
  console.log(user);

  docheckphone({ tel: user.tel }).then(({ data: res }) => {
    // console.log(res);
    if (res.code == 10005) {
      showFailToast("手机号已被注册");
      return;
    }
    localStorage.setItem("tel", user.tel);
    router.push("/register/code");
  });
};
</script>

<style>
</style>